/*
 *  Copyright 2011-2012 Redia A/S
 * 
 *  This file is part of Redias Android Utilities.
 *
 *  Redias Android Utilities is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Redias Android Utilities is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with Redias Android Utilities.  If not, see <http://www.gnu.org/licenses/>.
 */
package dk.redia.lib.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {

	public static Date parseInfoObjectTime(String time) {
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		try {
			Date parsed = sf.parse(time);
			return parsed;
		} catch (ParseException e) {
			e.printStackTrace();
			return new Date();
		}
		
	}
	
	public static String formatTime(Date time) {
		if (time==null) {
			time = new Date();
		}
		SimpleDateFormat sf = new SimpleDateFormat("dd/MM yyyy 'kl.' HH:mm");
		return sf.format(time);
	}
	
	public static String formatDate(Date time) {
		if (time==null) {
			time = new Date();
		}
		SimpleDateFormat sf = new SimpleDateFormat("dd/MM yyyy");
		return sf.format(time);
	}
	
	public static int getUnixTime(Date time) {
		return (int) (time.getTime() / 1000L);
	}
	
	public static int getCurrentUnixTime() {
		return (int) (System.currentTimeMillis() / 1000L);
	}

	public static Date fromUnixTimeStamp(int timestamp) {
		return new Date(1000L * timestamp);
	}
}
